import request from '@/utils/request'

export default {
  // 接受父组件的值 通过外部磋商创建虚拟机
  props: {
    vId: String
  },
  name: 'vmList',
  data() {
    return {
      jsonUrl: '../../../../../static/testapi.json',
      // card1
      cloudPlatformList: [],
      archList: [
        {"type": "X86_64", "value": "X86_64"},
        {"type": "ARM64", "value": "ARM64"}
      ],
      instanceChargeTypeList: [
        {"type": "POSTPAID", "name": "按量付费", "description": "先使用后付费，按需开通", "disabled": false},
        {"type": "PREPAID", "name": "包年包月", "description": "先付费后使用价格优惠", "disabled": true}
      ],
      vpcList: [],
      switchList: [],
      regionList: [],
      zoneList: [],
      instanceFamilyList: [],
      instanceTypeList: [],
      sysDiskTypeList: [],
      dataDiskTypeList: [],
      securityGroupList: [],
      baseForm: {
        instanceChargeType: 'POSTPAID',
        cloudPlatformId: '',
        location: '',
        regionId: '',
        regionName: '',
        zoneId: '',
        arch: 'X86_64',
        vpcId: '',
        switchId: '',
        instanceFamilyId: '',
        instanceType: '',
        cpuCoreCount: null,
        memorySize: null,
        architecture: null,
        imagePlatform: '',
        imageId: '',
        securityGroups: [],
        instanceName: '',
        hostname: '',
        description: '',
        internetChargeType: 'PAYBYTRAFFIC',
        internetMaxBandwidthOut: 1,
        publicIP: true,
      },
      loading: {
        regionId: false,
        zoneId: false,
        vpcId: false,
        switchId: false,
        instanceFamilyId: false,
        instanceType: false,
        imagePlatform: false,
        imageId: '',
        sysDiskType: false
      },
      // card2
      vCPUList: [{"value": 1, "label": "1 vCPU"}, {"value": 2, "label": "2 vCPU"}, {"value": 4, "label": "4 vCPU"}, {"value": 8, "label": "8 vCPU"}, {"value": 16, "label": "16 vCPU"}, {"value": 32, "label": "32 vCPU"}],
      memoryList: [{"value": 1, "label": "1 GiB"}, {"value": 2, "label": "2 GiB"}, {"value": 4, "label": "4 GiB"}, {"value": 8, "label": "8 GiB"}, {"value": 16, "label": "16 GiB"}, {"value": 32, "label": "32 GiB"}],
      // 实例
      instanceList: [],
      imageList: [],
      pagination: {
        currentPage: 1,
        size: 5,
        total: 0
      },
      activeSpecTab: '1',
      specParamDialogVisible: false,
      specParamList: [],
      isIndeterminate: true,
      checkAllSpecParams: false,
      checkedSpecParamsTemp: [], // 选择展示的参数
      checkedSpecParams: [], // 确认选择展示的参数
      specParamsTableColumnVisible: {

      },
      architectureList: [],
      updateSelect: true,

      // 镜像
      activeMirrorTab: '1',
      commonMirrorList: [],
      // 镜像操作系统,
      imagePlatform: [],
      commonMirrorVersionList: [],

      instanceForm: {
        vCPUId: '',
        memoryId: '',
        specificationName: '',
        architecture: {
          architectureId: '',
          typeId: ''
        },
        selectedInstanceId: '', // 所选表格中实例
        commonMirrorId: '',
        commonMirrorVersionId: ''
      },

      // card3
      diskTypeList: [],
      dataDiskMax: 5, // 设置最大行数为5
      diskForm: {
        systemDiskList: [
          { type: null, capacity: null, quantity: null, iops: '-', performance: '-', release: true }
        ],
        dataDiskList: []
      },
      // card4 带宽和安全组
      bandwidthForm: {
        billingMode: 'fixed',
        group: '0',
        securityGroupName: '',
        securityGroupType: 'normal',
        IPv4Ports: []
      },
      IPv4PortList: [],

      // card 5 高级选项
      advancedOptionForm: {
        instanceName: '',
        description: '',
        hostname: ''
      },
      advancedOptionFormRules: {
        instanceName: [
          // { required: true, message: '请输入实例名称', trigger: 'blur' },
          { min: 2, max: 128, message: '实例名称长度为2-128个字符', trigger: 'blur' },
          {
            pattern: /^[\u4e00-\u9fa5a-zA-Z]/,
            message: '实例名称需以字母或中文开头',
            trigger: 'blur'
          }
        ],
        description: [
          { min: 2, max: 256, message: '描述长度为2-256个字符', trigger: 'blur' },
          {
            pattern: /^(?!https?:\/\/|https:\/\/)[\s\S]+$/,
            message: '描述不能以http://或https://开头',
            trigger: 'blur'
          }
        ],
        hostname: [
          { min: 2, max: 64, message: '主机名称长度为2-64个字符', trigger: 'blur' },
          {
            pattern: /^[a-zA-Z0-9-.]+$/,
            message: '主机名称只能使用大小写字母、数字、-和.',
            trigger: 'blur'
          },
          {
            pattern: /^(?!.*(\.\.|\. -|-\.|- -))[\s\S]+$/,
            message: '主机名称不能连续使用-和.',
            trigger: 'blur'
          },
          {
            pattern: /^[^-].*[^-.]$/,
            message: '主机名称不能以-和.结尾',
            trigger: 'blur'
          }
        ]
      },
      // card right
      payForm: {
        instanceNum: 1,
        duration: ' ',
        autoRenew: false
      },
      maxInstanceNum: 1, // 最大购买实例数
      durationList: [],
      trueBool: true,
      price: {
        tradePrice: '',
        bandwidthPrice: ''
      },
      selectedRows: []
    }
  },
  created() {
  },
  computed: {
    selectedRegion() {
      return this.baseForm.regionName ? this.baseForm.regionName : ''
    },
    selectedZone() {
      const option = this.zoneList.find(i => i.zoneId === this.baseForm.zoneId)
      return option ? option.localName : ''
    },
    selectedVpc() {
      const option = this.vpcList.find(i => i.vpcId === this.baseForm.vpcId)
      return option ? option.vpcName : ''
    },
    selectedSwitch() {
      const optionSwitch = this.switchList.find(i => i.vSwitchId === this.baseForm.switchId)
      return optionSwitch ? optionSwitch.vSwitchName : ''
    },
    selectedInstanceType() {
      if (this.baseForm.instanceType) {
        const option = this.instanceTypeList.find(i => i.instanceType === this.baseForm.instanceType)
        return option ? option.instanceTypeName : ''
      }
      return ''
    },
    selectedImage() {
      const option = this.imageList.find(i => i.id === this.baseForm.imageId)
      return option ? option.name : ''
    },
    selectedSystemDisk() {
      if (this.diskForm.systemDiskList[0]) {
        const type = this.diskForm.systemDiskList[0].type
        const capacity = this.diskForm.systemDiskList[0].capacity
        return type && capacity ? capacity + " GB" : ''
      }
      return ''
    },
    selectedBandwidth() {

      if (this.baseForm.publicIP) {
        const type = this.baseForm.internetChargeType === 'PAYBYTRAFFIC' ? '按使用流量' : '按固定带宽'
        return type + ' ' + this.baseForm.internetMaxBandwidthOut + 'Mbps'
      } else {
        return '您没有为实例分配公网IP地址'
      }
    },
    selectedSecurityGroup() {
      const option = this.baseForm.securityGroups.map(s => s.securityGroupName)
      return option ? option.join(',') : ''
    },
    // 确认按钮
    createInstanceDisabled() {
      return !(this.selectedRegion && this.selectedZone
        && this.selectedVpc && this.selectedSwitch
        && this.selectedInstanceType && this.selectedImage
        && this.selectedSystemDisk && this.selectedSecurityGroup)
    },
    // 数据盘上限
    isMaxRowsReached() {
      return this.diskForm.dataDiskList.length >= this.dataDiskMax
    }
  },
  // 监听计算价格
  watch: {
    baseForm: {
      deep: true,
      handler: function (newValue, oldValue) {
        this.instancePrice();
      }
    },
    diskForm: {
      deep: true,
      handler: function (newValue, oldValue) {
        this.instancePrice();
      }
    },
    // 通过外部磋商创建虚拟机
    vId(newValue) {
      // console.log('Parent component changed the value to', newValue);
      this.consultSelected()
    }
  },
  async mounted() {
    await this.getCloudPlatformList()
    this.consultSelected()
  },
  methods: {
    // 如果是iframe嵌入本页面，则选中云商
    consultSelected() {
      if (this.vId != null && this.vId != '') {
        this.baseForm.cloudPlatformId = this.vId
        this.changeCloudPlatform()
      }
    },
    // 云商列表
    getCloudPlatformList() {
      request({
        url: '/cloud/pub/v1.0/cloud_platform',
        method: 'get',
        params: {
          pageNo: 1,
          pageSize: 100
        }
      }).then(({data}) => {
        this.cloudPlatformList = data.pageData
        if (this.cloudPlatformList.length > 0) {
          if (this.vId == null || this.vId == '') {
            this.baseForm.cloudPlatformId = this.cloudPlatformList[0].id
          }
          this.changeCloudPlatform()
          // change other
          // this.getRegionList();
          this.getDurationList()
        }
      })
    },
    // 切换云平台时
    changeCloudPlatform() {
      // 有时候this.cloudPlatformList为空
      this.baseForm.regionId = this.cloudPlatformList.filter(c => c.id == this.baseForm.cloudPlatformId)[0].regionId
      this.baseForm.regionName = this.cloudPlatformList.filter(c => c.id == this.baseForm.cloudPlatformId)[0].regionName
      this.baseForm.zoneId = ''
      this.baseForm.vpcId = ''
      this.baseForm.switchId = ''
      this.baseForm.instanceFamilyId = ''
      this.baseForm.instanceType = ''
      this.regionList = []
      this.zoneList = []
      this.vpcList = []
      this.switchList = []
      this.instanceFamilyList = []
      this.instanceTypeList = []
      // this.getRegionList()
      // 包年包月时间
      this.getDurationList()
      // 清空磁盘类型
      this.dataDiskTypeList = []
      this.sysDiskTypeList = []
      // 清空磁盘内容
      this.diskForm.dataDiskList = []
      this.diskForm.systemDiskList[0] = { type: null, capacity: null, quantity: null, iops: '-', performance: '-', release: true }
      //
      this.getZoneList()
      // this.getInstanceFamilyList()
      // this.getInstanceTypeList()
      // this.getImagePlatform()
      // this.getSecurityGroupList()
    },
    changeZoneList() {
      this.baseForm.vpcId = ''
      this.baseForm.switchId = ''
      this.baseForm.instanceFamilyId = ''
      this.baseForm.instanceType = ''
      this.vpcList = []
      this.switchList = []
      this.instanceFamilyList = []
      this.instanceTypeList = []
      // 清空磁盘类型
      this.dataDiskTypeList = []
      this.sysDiskTypeList = []
      // 清空磁盘内容
      this.diskForm.dataDiskList = []
      this.diskForm.systemDiskList[0] = { type: null, capacity: null, quantity: null, iops: '-', performance: '-', release: true }
      //
      this.getVpcList()
      this.getInstanceFamilyList()
      this.getInstanceTypeList()
    },
    // 切换网络
    changeVpcList() {
      this.baseForm.switchId = ''
      this.switchList = []
      this.getSwitchList()
      this.getSecurityGroupList()
    },
    // 包年包月时间
    getDurationList() {
      let _self = this
      request({
        url: '/cloud/pub/v1.0/duration_available?dataCenterId=' + this.baseForm.cloudPlatformId,
        method: 'get'
      }).then(data => {
        _self.durationList = data.data
        if (_self.durationList.length > 0) {
          _self.payForm.duration = this.durationList[0].id
        }
      }).catch(error => {
        console.error(error)
      })
    },
    // 获取可用区
    getZoneList() {
      let _self = this
      _self.loading.zoneId = true
      request({
        url: '/cloud/pub/v1.0/regions_zones/zone?dataCenterId=' + this.baseForm.cloudPlatformId + '&regionUuid=' + this.baseForm.regionId,
        method: 'get'
      }).then(data => {
        _self.loading.zoneId = false
        this.zoneList = data.data
        if (this.zoneList.length > 0) {
          this.baseForm.zoneId = this.zoneList[0].zoneId
          this.changeZoneList()
        }
      }).catch(error => {
        _self.loading.zoneId = false
      })
    },
    // 获取专有网络
    getVpcList() {
      let _self = this
      _self.loading.vpcId = true
      request({
        url: '/cloud/pub/v1.0/vpc/getVpcList?dataCenterId=' + this.baseForm.cloudPlatformId + '&regionUuid=' + this.baseForm.regionId,
        method: 'get'
      }).then(data => {
        _self.loading.vpcId = false
        this.vpcList = data.data.pageData
        if (this.vpcList.length > 0) {
          this.baseForm.vpcId = this.vpcList[0].vpcId
          this.changeVpcList()
        }
      }).catch(error => {
        _self.loading.vpcId = false
      })
    },
    // 获取专有网络
    getSwitchList() {
      let _self = this
      _self.loading.switchId = true
      request({
        url: '/cloud/pub/v1.0/switch/getSwitchList',
        method: 'get',
        params: {
          dataCenterId: this.baseForm.cloudPlatformId,
          regionId: this.baseForm.regionId,
          zoneId: this.baseForm.zoneId,
          vpcId: this.baseForm.vpcId,
        }
      }).then(data => {
        _self.loading.switchId = false
        this.switchList = data.data.pageData
        if (this.switchList.length > 0) {
          this.baseForm.switchId = this.switchList[0].vSwitchId
        }
      }).catch(error => {
        _self.loading.switchId = false
      })
    },
    // 实例族
    getInstanceFamilyList() {
      let _self = this
      _self.loading.instanceFamilyId = true
      request({
        url: '/cloud/pub/v1.0/instanceTypes/listInstanceFamily',
        method: 'get',
        params: {
          dataCenterId: this.baseForm.cloudPlatformId,
          regionId: this.baseForm.regionId
        }
      }).then(data => {
        _self.loading.instanceFamilyId = false
        this.instanceFamilyList = data.data
      }).catch(error => {
        _self.loading.instanceFamilyId = false
      })
    },
    // 实例规格
    getInstanceTypeList() {
      let _self = this
      _self.loading.instanceType = true
      _self.baseForm.instanceType = ''
      request({
        url: '/cloud/pub/v1.0/instanceTypes/list',
        method: 'get',
        params: {
          dataCenterId: this.baseForm.cloudPlatformId,
          regionId: this.baseForm.regionId,
          zoneId: this.baseForm.zoneId,
          pageNumber: this.pagination.currentPage,
          pageSize: this.pagination.size,
          instanceTypeFamily: this.baseForm.instanceFamilyId,
          cpuCoreCount: this.baseForm.cpuCoreCount,
          memorySize: this.baseForm.memorySize,
          arch: this.baseForm.arch
        }
      }).then(data => {
        _self.loading.instanceType = false
        this.pagination.total = data.data.total
        this.instanceTypeList = data.data.pageData
      }).catch(error => {
        _self.loading.instanceType = false
      })
    },
    // 修改实例规格
    selectInstanceType(selection, row) {
      if (selection.length > 1) {
        let del_row = selection.shift()
        this.$refs.instanceTypeList.toggleRowSelection(del_row, false)
      }
      this.baseForm.instanceType = row.instanceType
      this.baseForm.imageId = ''
      this.baseForm.imagePlatform = ''
      this.getDiskData();
      this.getImagePlatform()
    },
    selectInstanceTypeAll(selection) {
      this.baseForm.instanceType = ''
      this.$refs.instanceTypeList.clearSelection();
    },
    getInstanceTypeKey(row) {
      return row.instanceType
    },
    // 镜像操作系统
    getImagePlatform() {
      let _self = this
      _self.loading.imagePlatform = true
      request({
        url: '/cloud/pub/v1.0/images/listPlatform',
        method: 'get',
        params: {
          dataCenterId: this.baseForm.cloudPlatformId,
          regionId: this.baseForm.regionId,
          instanceType: this.baseForm.instanceType
        }
      }).then(data => {
        _self.loading.imagePlatform = false
        this.imagePlatform = data.data
      }).catch(error => {
        _self.loading.imagePlatform = false
      })
    },
    getImageList() {
      let _self = this
      _self.loading.imageId = true
      _self.baseForm.imageId = ''
      request({
        url: '/cloud/pub/v1.0/images/list',
        method: 'get',
        params: {
          dataCenterId: this.baseForm.cloudPlatformId,
          regionId: this.baseForm.regionId,
          platform: this.baseForm.imagePlatform,
          arch: this.baseForm.arch,
          instanceType: this.baseForm.instanceType
        }
      }).then(data => {
        _self.loading.imageId = false
        this.imageList = data.data.pageData
        if (this.imageList.length > 0) {
          this.baseForm.imageId = this.imageList[0].id
        }
      }).catch(error => {
        _self.loading.imageId = false
      })
    },
    // 磁盘类型
    getDiskData() {
      let _self = this
      _self.loading.sysDiskType = true
      _self.loading.dataDiskType = true
      // 清空磁盘类型
      _self.dataDiskTypeList = []
      _self.sysDiskTypeList = []
      // 清空磁盘内容
      _self.diskForm.dataDiskList = []
      _self.diskForm.systemDiskList = []
      // 系统磁盘类型
      request({
        url: '/cloud/pub/v1.0/disk_type/listSystemDiskType',
        method: 'get',
        params: {
          dataCenterId: this.baseForm.cloudPlatformId,
          regionId: this.baseForm.regionId,
          zoneId: this.baseForm.zoneId,
          instanceType: this.baseForm.instanceType
        }
      }).then(data => {
        this.sysDiskTypeList = data.data
        if (this.sysDiskTypeList.length > 0) {
          this.diskForm.systemDiskList.push({
            type: this.sysDiskTypeList[0].diskType,
            capacity: this.sysDiskTypeList[0].min,
            quantity: null,
            iops: '-',
            performance: '-',
            release: true
          })
        }
      }).catch(error => {
        _self.loading.sysDiskType = false
      })
      // 数据盘类型
      request({
        url: '/cloud/pub/v1.0/disk_type/listDataDiskType',
        method: 'get',
        params: {
          dataCenterId: this.baseForm.cloudPlatformId,
          regionId: this.baseForm.regionId,
          zoneId: this.baseForm.zoneId,
          instanceType: this.baseForm.instanceType
        }
      }).then(data => {
        this.dataDiskTypeList = data.data
      }).catch(error => {
        _self.loading.dataDiskType = false
      })
    },
    // 安全组动作
    handleSecurityGroupChange(val) {
      this.baseForm.securityGroups = val;
    },
    // 安全组
    getSecurityGroupList() {
      let _self = this
      request({
        url: '/cloud/pub/v1.0/security_group/listSecurityGroup',
        method: 'get',
        params: {
          dataCenterId: this.baseForm.cloudPlatformId,
          regionId: this.baseForm.regionId,
          vpcId: this.baseForm.vpcId
        }
      }).then(data => {
        _self.securityGroupList = data.data
      }).catch(error => {
      })
    },
    // 规格参数全选按钮
    handleCheckAllChange(val) {
      if (val) {
        this.checkedSpecParamsTemp = this.specParamList
      } else {
        this.checkedSpecParamsTemp = []
        for (let i = 0; i < this.specParamList.length; i++) {
          if (this.specParamList[i].originalShow === true) {
            this.checkedSpecParamsTemp.push(this.specParamList[i])
          }
        }
      }

      this.isIndeterminate = false
    },

    // 选择更多参数
    handleCheckedSpecParamsChange(value) {
      const checkedCount = value.length
      this.checkAllSpecParams = checkedCount === this.specParamList.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.specParamList.length
    },
    // 取消选择更多参数
    cancelCheckedSpecParamsChange() {
      this.specParamDialogVisible = false
      this.checkedSpecParamsTemp = this.checkedSpecParams
      const checkedCount = this.checkedSpecParams.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.specParamList.length
    },
    // 确认选择更多参数
    confirmCheckedSpecParamsChange() {
      this.checkedSpecParams = this.checkedSpecParamsTemp
      this.specParamDialogVisible = false
      const checkedCount = this.checkedSpecParams.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.specParamList.length
    },
    // 确认选择更多参数表格联动
    getTableColumVisible(label) {
      for (let i = 0; i < this.checkedSpecParams.length; i++) {
        if (this.checkedSpecParams[i].label === label) {
          return true
        }
      }
      return false
    },

    // 选择架构及下拉列表内容
    changeSelectedArchitecture(architecture) {
      // 不然不重新渲染...
      this.updateSelect = false
      this.$nextTick(() => {
        this.updateSelect = true
      })
      if (architecture.id === this.instanceForm.architecture.architectureId) {
        this.instanceForm.architecture.typeId = architecture.checkedType
      }
    },
    // 选择架构
    changeArch() {
      this.pagination.currentPage = 1
      this.getInstanceTypeList()
    },
    // 实例调整分页
    handleCurrentChange(val) {
      this.pagination.currentPage = val
      this.getInstanceTypeList()
    },
    // 数据盘添加一行
    addDataDiskRow() {
      if (this.diskForm.dataDiskList.length < this.dataDiskMax) {
        const type = this.dataDiskTypeList[0].diskType
        this.diskForm.dataDiskList.push({
          type: type,
          capacity: this.dataDiskTypeList[0].min,
          quantity: null,
          iops: '-',
          performance: '-',
          release: true,
        })
      }
    },
    // 数据盘删除一行
    deleteDataDiskRow(index) {
      this.diskForm.dataDiskList.splice(index, 1)
    },
    createNetwork() {},
    createSwitch() {},
    cancel() {
      this.$router.push({name: 'pubVmList'})
    },
    // 创建虚拟机
    createInstance() {
      // 数据盘
      let dataDisk = []
      for (let item of this.diskForm.dataDiskList) {
        dataDisk.push({diskType: item.type, diskSize: item.capacity})
      }

      let createVMReq = {
        instanceChargeType: this.baseForm.instanceChargeType,
        cloudPlatformId: this.baseForm.cloudPlatformId,
        regionId: this.baseForm.regionId,
        zoneId: this.baseForm.zoneId,
        vpcId: this.baseForm.vpcId,
        switchId: this.baseForm.switchId,
        instanceType: this.baseForm.instanceType,
        imageId: this.baseForm.imageId,
        sysDisk: {
          diskType: this.diskForm.systemDiskList[0].type,
          diskSize: this.diskForm.systemDiskList[0].capacity
        },
        dataDisk: dataDisk,
        securityGroupIds: this.baseForm.securityGroups.map(s => s.securityGroupId),
        instanceName: this.baseForm.instanceName,
        hostname: this.baseForm.hostname,
        description: this.baseForm.description,
        publicIP: this.baseForm.publicIP,
        internetChargeType: this.baseForm.internetChargeType,
        internetMaxBandwidthOut: this.baseForm.internetMaxBandwidthOut,
        period: this.baseForm.instanceChargeType == 'PREPAID' ? durationOption.period: 0,
        priceUnit: this.baseForm.instanceChargeType == 'PREPAID' ? durationOption.unit : 'Year',
      }

      console.log(createVMReq)

      request({
        url: '/cloud/pub/v1.0/virtualMachine/create',
        method: 'post',
        data: createVMReq
      }).then(data => {
        this.$message({type: 'success', message: '任务提交成功!'})
        this.$router.push({name: 'pubVmList'})
      }).catch(error => {
        console.error(error)
      })
    },
    // 实例询价
    instancePrice() {
      if (!this.createInstanceDisabled) {
        // 数据盘
        let dataDisk = []
        for (let item of this.diskForm.dataDiskList) {
          dataDisk.push({diskType: item.type, diskSize: item.capacity})
        }
        // 包月包年的时长
        const durationOption = this.durationList.find(i => i.id === this.payForm.duration)
        let _self = this
        let req = {
          amount: 1,
          dataCenterId: this.baseForm.cloudPlatformId,
          regionId: this.baseForm.regionId,
          zoneId: this.baseForm.zoneId,
          instanceType: this.baseForm.instanceType,
          imageId: this.baseForm.imageId,
          instanceChargeType: this.baseForm.instanceChargeType,
          internetChargeType: this.baseForm.publicIP ? this.baseForm.internetChargeType : 'PREPAID',
          internetMaxBandwidthOut: this.baseForm.publicIP ? this.baseForm.internetMaxBandwidthOut : 0,
          systemDisk: {
            diskType: this.diskForm.systemDiskList[0].type,
            diskSize: this.diskForm.systemDiskList[0].capacity
          },
          dataDisks: dataDisk,
          period: this.baseForm.instanceChargeType == 'PREPAID' ? durationOption.period: 0,
          priceUnit: this.baseForm.instanceChargeType == 'PREPAID' ? durationOption.unit : 'Year',
        }
        request({
          url: '/cloud/pub/v1.0/inquiry_rice/inquiry',
          method: 'post',
          data: req
        }).then((data) => {
          _self.price.tradePrice = data.data.tradePrice
          _self.price.bandwidthPrice = data.data.bandwidthPrice
        })
      }
    },
  }
}
